package com.sso.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.sso.dao.UserMapper;
import com.sso.domain.User;
import com.sso.service.UserService;
import com.sso.util.CheckResult;
import com.sso.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;

@Service(interfaceClass = UserService.class,protocol = "dubbo")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public String login(User user) {
        User loginUser = userMapper.getByUsernameAndPassword(user);
        if (loginUser == null) {
            return null;
        }
        String jwt = JwtUtils.createJWT(user.getId(), user.getUsername());
        return jwt;
    }

    @Override
    public boolean validateJwt(String jwt) {
        CheckResult checkResult = JwtUtils.validateJWT(jwt);
        return checkResult.getSuccess();
    }
}
